<?php

namespace App\Imports;


use App\Models\ExhibitorInformation;


use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\ToArray;
use Maatwebsite\Excel\Concerns\WithChunkReading;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

 class ExhibitorInformationImport implements ToArray, WithChunkReading, WithHeadingRow
{
    public function startRow(): int
    {
        return 1;
    }

    public function array(array $rows)
    {

        $data = [];
        $now = date('Y-m-d H:i:s');
        foreach ($rows as $row) {
dump($rows);
            $data[] = [
                'id' => $row['id'],
                'number' => 0,
                'parent_id' => 0,
                'type' => 1,
                'question' => $row['ques'],
                'standard_answer' => $row['answer'],
                'ai_ques_id' => $row['aiid'],
                'created_at' => $now
            ];
        }

        if (!$data) {
            throw new ApiException('没有要导入的数据');
            return false;
        };

        //全部导入
        DB::select('TRUNCATE table questions_copy1');

        DB::table('questions_copy1')->insert($data);

        return true;
    }

    //批量导入1000条
    public function batchSize(): int
    {
        return 1000;
    }

    //以1000条数据基准切割数据
    public function chunkSize(): int
    {
        return 1000;
    }

    public function endColumn(): string
    {
        return $this->endColumn();
    }
}
